package com.jyy.prefabricated.service.impl;

import com.jyy.prefabricated.dto.BatchDto;
import com.jyy.prefabricated.entity.ExamPaperGoods;

import com.jyy.prefabricated.mapper.ExamPaperGoodsMapper;
import com.jyy.prefabricated.service.ExamPaperGoodsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 练习关联项目课程表(ExamPaperGoods)表服务实现类
 *
 * @author makejava
 * @since 2021-05-28 10:07:03
 */
@Service("examPaperGoodsService")
public class ExamPaperGoodsServiceImpl implements ExamPaperGoodsService {
    @Resource
    private ExamPaperGoodsMapper examPaperGoodsMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ExamPaperGoods queryById(Integer id) {
        return this.examPaperGoodsMapper.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<ExamPaperGoods> queryAllByLimit(int offset, int limit) {
        return this.examPaperGoodsMapper.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param examPaperGoods 实例对象
     * @return 实例对象
     */
    @Override
    public ExamPaperGoods insert(ExamPaperGoods examPaperGoods) {
        this.examPaperGoodsMapper.insert(examPaperGoods);
        return examPaperGoods;
    }

    /**
     * 修改数据
     *
     * @param examPaperGoods 实例对象
     * @return 实例对象
     */
    @Override
    public ExamPaperGoods update(ExamPaperGoods examPaperGoods) {
        this.examPaperGoodsMapper.update(examPaperGoods);
        return this.queryById(examPaperGoods.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.examPaperGoodsMapper.deleteById(id) > 0;
    }

    @Override
    public int batchUpdateDeleted(BatchDto dto) {
        return examPaperGoodsMapper.batchUpdateDeleted(dto);
    }

    @Override
    public List<ExamPaperGoods> queryList(ExamPaperGoods examPaperGoods) {
        examPaperGoods.setDeleted(false);
        return examPaperGoodsMapper.queryAll(examPaperGoods);
    }
}
